In firefox, onload will trigger when the image is loaded, but at
that point it may not be decoded yet so showing it will sometimers
trigger flashes. We use the new decode() feature instead which ensures
both that the image is loaded *and* decoded, thus fixing the flashes.
var image = new Image();
image.src = this.url;
this.image = image;
+ this.decoded = image.decode();
textures[id] = this;
}
outstandingDisplayCommands = display_commands;
if (new_textures.length > 0) {
- var n_textures = new_textures.length;
+ var decodes = [];
for (var i = 0; i < new_textures.length; i++) {
- var t = new_textures[i];
- t.image.onload = function() {
- n_textures -= 1;
- if (n_textures == 0) {
- handleOutstandingDisplayCommands();
- }
- };
+ decodes.push(new_textures[i].decoded);
}
+ Promise.allSettled(decodes).then(
+ () => {
+ handleOutstandingDisplayCommands();
+ });
} else {
handleOutstandingDisplayCommands();
}